package com.liuliu.zua.service.impl;

import com.liuliu.common.core.domain.entity.SysUser;
import com.liuliu.common.utils.DateUtils;
import com.liuliu.system.mapper.SysUserMapper;
import com.liuliu.zua.domain.ZuaCourse;
import com.liuliu.zua.domain.ZuaGradeStudent;
import com.liuliu.zua.mapper.ZuaCourseMapper;
import com.liuliu.zua.mapper.ZuaGradeStudentMapper;
import com.liuliu.zua.service.IZuaGradeStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 成绩Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-03-22
 */
@Service
@SuppressWarnings("all")
public class ZuaGradeStudentServiceImpl implements IZuaGradeStudentService
{
    @Autowired
    private ZuaCourseMapper zuaCourseMapper;
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private ZuaGradeStudentMapper zuaGradeStudentMapper;

    /**
     * 查询成绩
     * 
     * @param gradeId 成绩ID
     * @return 成绩
     */
    @Override
    public ZuaGradeStudent selectZuaGradeStudentById(Long gradeId)
    {
        return zuaGradeStudentMapper.selectZuaGradeStudentById(gradeId);
    }

    /**
     * 查询成绩列表
     * 
     * @param zuaGradeStudent 成绩
     * @return 成绩
     */
    @Override
    public List<ZuaGradeStudent> selectZuaGradeStudentList(ZuaGradeStudent zuaGradeStudent)
    {
        return zuaGradeStudentMapper.selectZuaGradeStudentList(zuaGradeStudent);
    }

    @Override
    public List<ZuaGradeStudent> selectZuaGradeStudentListByLoginId(ZuaGradeStudent zuaGradeStudent) {
        return zuaGradeStudentMapper.selectZuaGradeStudentListByLoginId(zuaGradeStudent);
    }

    /**
     * 新增成绩
     * 
     * @param zuaGradeStudent 成绩
     * @return 结果
     */
    @Override
    public int insertZuaGradeStudent(ZuaGradeStudent zuaGradeStudent)
    {
        zuaGradeStudent.setCreateTime(DateUtils.getNowDate());
        return zuaGradeStudentMapper.insertZuaGradeStudent(zuaGradeStudent);
    }

    /**
     * 修改成绩
     * 
     * @param zuaGradeStudent 成绩
     * @return 结果
     */
    @Override
    public int updateZuaGradeStudent(ZuaGradeStudent zuaGradeStudent)
    {
        SysUser sysUser = sysUserMapper.selectByNickName(zuaGradeStudent.getStudentId());
        zuaGradeStudent.setStudentId(String.valueOf(sysUser.getUserId()));
        ZuaCourse zuaCourse = zuaCourseMapper.selectZuaCourseByCourseName(zuaGradeStudent.getCourseId());
        zuaGradeStudent.setCourseId(String.valueOf(zuaCourse.getCourseId()));
        zuaGradeStudent.setUpdateTime(DateUtils.getNowDate());
        return zuaGradeStudentMapper.updateZuaGradeStudent(zuaGradeStudent);
    }

    /**
     * 批量删除成绩
     * 
     * @param gradeIds 需要删除的成绩ID
     * @return 结果
     */
    @Override
    public int deleteZuaGradeStudentByIds(Long[] gradeIds)
    {
        return zuaGradeStudentMapper.deleteZuaGradeStudentByIds(gradeIds);
    }

    /**
     * 删除成绩信息
     * 
     * @param gradeId 成绩ID
     * @return 结果
     */
    @Override
    public int deleteZuaGradeStudentById(Long gradeId)
    {
        return zuaGradeStudentMapper.deleteZuaGradeStudentById(gradeId);
    }
}
